{extend name="platform/base" /}
{block name="resources"}
<!-- <link rel="stylesheet" type="text/css" href="ADMIN_CSS/haidao.css"> -->
<!-- <link rel="stylesheet" type="text/css" href="ADMIN_CSS/admin.css"> -->
<style>
.btn-test{
	font-family: "microsoft yahei";
	border-radius: 4px;
	padding: 5px 20px;
	background-color: #51A351;
	color: #FFF;
	margin: 0 10px;
	border: none;
}
.Switch_FlatCircular {
    line-height: 30px;
}
.left_main{
    width: 23%;
    float: left;
	border:1px solid #E3E3E3;
	height: 524px;
}
ul{
    margin: 10px;
}
ul a.active{
	color:#11B9ED;
}
ul a:hover{
	color:#11B9ED;
}
.leftcheckbox{
	float:right;
}
.left_main li{
	line-height:30px;
	padding:2px 6px;
	border:1px dotted #E3E3E3;
	margin-bottom: 10px;
	list-style-type: none;
}
ul a{
	color:#666;
}
a:hover{
	color:#11B9ED;
}
.right_main{
	width:75%;
	float:right;
	border:1px solid #E3E3E3;
	height: 400px;
}
.main-top{
	height: 30px;
    line-height: 30px;
    padding: 0 10px;
	color: #666;
    border-bottom: 1px solid #E3E3E3; 
	margin-bottom: 15px;
}
.email_title{
	width:81px;
	line-height: 40px;
    float: left;
	padding-left: 10px;
}
.edit_bat{
    width: 250px;
    float: left;
    margin-left: 20px;
    line-height: 40px;
}
.save{
	clear:both;
	text-align:center;
	margin-top:10px;
	display: inline-block;
	width:100%;
/* 	line-height:40px; */
}
input[type="submit"], input.submit, a.submit {
    
     display: inline-block; 
   
}


.back{
	background: #e5e5e5;
    border: 0;
    height: 30px;
    width: 66px;
}
.rightlist{
	clear: both;
    content: '';
    display: inline-block;
/* 	color:#fff; */
}
.right-item{
	width: 12%;
}
.itemlist{
	padding: 0 2px;
    margin: 5px;
/*     background: rgb(0, 192, 255); */
/* 	width: 9%; */
	float:left;
	text-align: center;
	color:#666;
}
.title-item{
	height: 40px;
	border-top:1px solid #E3E3E3;
/* 	border-bottom:1px solid #E3E3E3; */
	color: #666;
}
.template-message{
	height: 40px;
    line-height: 40px;
    border: 1px solid #e5e5e5;
    border-bottom: none;
	
}  
h1{
    width: 2px;
    height: 20px;
    float: left;
    background-color: #11B9ED;
}
.active{
	color:#11B9ED;	
}
.tab-pane{
	clear: both;
    content: '';
/*     display: inline-block; */
}
.msg{
    display: inline-block;
    width: 100%;
    color: #FF8400;
	height: 40px;
    line-height: 40px;
    padding-left: 10px;
}
.senditem{
	border: 1px solid #11B9ED;
    margin: 9px;
	border-radius: 3px;
	width:30%;
}
.qianming{
	display: inline-block;
    line-height: 40px;
    margin-left: 10px;
	color:#666;
	width:100%;
}
.bl{
	color:#666;
	margin-left:10px;
	display: inline-block;
	line-height:35px;
	width:100%;
}
input[type="text"]{
	vertical-align: middle;
	margin-bottom:0;
}
</style>
{/block}
{block name="main"}
<!-- 邮箱设置 -->
<input type="hidden" id="curr_selectid" value="{$template_select.template_code}"/>
<div class="set-style">
<div class="template-message"><h1></h1><p style="width:90%;margin: 9px 7px 10px;">短信通知模板</p></div>
	<div class="tab-pane active">
		<div class="left_main">
			<ul>
				{volist name="template_type_list" id="template_item"}
					<a href="javascript:void(0);" onclick="template_onclick(this);" id="{$template_item.template_code}" style="text-decoration: none;" class="{$i == 1?'active':null}">
						<li>{$template_item.template_name}
							<label class="switch" style="float:right;">
								<input type="checkbox" id="adminCode" {if condition="$template_item.is_enable eq 1"}checked="checked"{/if} name="{$template_item.template_code}" onchange="check_change(this);">
								<span></span>
							</label>
						</li>
					</a>
				{/volist}
			</ul>
		</div>
		<div class="right_main">
			<div class="main-top">您正在编辑<a style="color:#11B9ED;" id="update_nameid"></a>通知模板</div>
			<div class="qianming"><div style="width:100px;float:left;">模板ID：</div><input type="text" id="template_titleid" value="{$template_select.template_title}" style="margin-right: 15px;height: 30px;line-height: 30px;" class="input-common" /><span style="font-size:13px;">必须与阿里大鱼的模板ID一致，否则无效!</span></div>
			<div class="qianming"><div style="width:100px;float:left;">短信签名：</div><input type="text" id="signNameid" style="margin-right: 15px;height: 30px;line-height: 30px;" value="{$template_select.sign_name	}" class="input-common" /><span style="font-size:13px;">与阿里大鱼内短信签名保持一致!</span></div>
			<div class="qianming"><div style="width:100px;float:left;">通知人手机号：</div><input type="text" id="notification_mode" style="margin-right: 15px;height: 30px;line-height: 30px;" value="{$template_select.notification_mode	}" class="input-common" /><span style="font-size:13px;">请输入通知人手机号，多个手机之间用英文逗号“,”隔开</span></div>
			<div class="bl">
				<div style="width:75px;float:left;">可用变量：</div>
				<div style="width:88%;float: left;font-size:13px;" id="user_variable">
					{foreach name="template_item_list" item="item_obj"}
						{$item_obj.replace_name}({$item_obj.item_name}),
					{/foreach}
				</div>
			</div>
		</div>
	</div>
	<div class="save">
		<input type="submit" value="保存" style="margin-right: 20px;width: 58px;height: 30px;border: 0;background-color: #5BB75B;color: #fff;"" onclick="template_submit();"/>
		<a href="{:__URL('PLATFORM_MAIN/config/notifyindex')}">
			<input type="button" value="返回" class="back" style="width: 66px;height:30px;"/>
		</a>
	</div>
								
</div>
{include file="platform/openDialog" /}

<script type="text/javascript">
var $template_array={$template_json};
var $template_send_item={$template_send_item_json};
var $is_first=1;
var $curr_select=$("#curr_selectid").val();
$("#"+$curr_select).click();

//左边模板菜单的点击函数
function template_onclick(event){
	$(event).parent('ul').find('a').removeClass('active');
	$(event).addClass('active');
	//处理新的以前 将上次改动的保存
	var $deal_type="";
	var $deal_title="";
	var $sign_name="";
	var $notification_mode = "";
	if($is_first==0){
		$deal_type=$("#curr_selectid").val();
		$deal_title=$("#template_titleid").val();
		$sign_name=$("#signNameid").val();
		$notification_mode=$("#notification_mode").val();
	}
	$template_type=$(event).attr("id");
	for($i=0; $i<$template_array.length;$i++){
		$template_obj=$template_array[$i];
		$template_obj_type=$template_obj.template_code;
		if($template_obj_type==$deal_type && $is_first==0){
			$template_array[$i].template_title=$deal_title;
			$template_array[$i].sign_name=$sign_name;
			$template_array[$i].notification_mode=$notification_mode;
		}
		if($template_obj_type==$template_type){
			$("#curr_selectid").val($template_type);
			$("#update_nameid").text($template_obj.template_name);
			$title=$template_obj.template_title;
			$("#template_titleid").val($title);
			$("#signNameid").val($template_obj.sign_name);
			$("#notification_mode").val($template_obj.notification_mode);
		}
	}
	$is_first=0;
	get_template_item($template_type);
}

function get_template_item($template_code){
	$.ajax({
		type : "post",
		url: "{:__URL('PLATFORM_MAIN/Config/getTemplateItem')}",
		data: {"template_code": $template_code },
		async : false, // 让它同步执行
		success: function (data) {
			var $html="";
			for($i=0;$i<data.length;$i++){
				$name=data[$i]["item_name"];
				$replace=data[$i]["replace_name"];
				if($html==""){
					$html=$replace+"("+$name+")";
				}else{
					$html=$html+","+$replace+"("+$name+")";
				}
			}
			$("#user_variable").html($html);
		}
	});
}

//开关关闭的点击事件
function check_change(event){
	var $type=$(event).attr("name");
	var $is_enable=0;
	if($(event).is(":checked")){
		$is_enable=1;
	}else{
		$is_enable=0;
	}
	for($i=0; $i<$template_array.length;$i++){
		$template_obj=$template_array[$i];
		$template_obj_type=$template_obj.template_code;
		if($template_obj_type==$type){
			$template_array[$i].is_enable=$is_enable;
		}
	}
}
function template_submit(){
	var $curr_select=$("#curr_selectid").val();
	$("#"+$curr_select).click();
	$.ajax({
		type : "post",
		url: "{:__URL('PLATFORM_MAIN/config/updatenotifytemplate')}",
		data: { "type": "sms", "template_data": JSON.stringify($template_array),"notify_type" : "business" },
		async : false, // 让它同步执行
		success: function (data) {
			if (data["code"] > 0) {
				showMessage('success', '提交成功');
				window.location.href=__URL("PLATFORM_MAIN/config/businessnotifytemplate?type=sms");
			}else{
				showMessage('error', '提交失败');
			}
		}
	});
}
</script>
{/block}